package test.common;

import com.alibaba.fastjson.annotation.JSONType;

/**
 * @author jack
 * @desc
 * @date 2022/3/28 13:31
 */
@JSONType(orders = {"respHead", "respBody", "signatureValue"})
public class ResponseMessage<T> {
    /**
     * 响应头
     */
    private RespHead respHead;
    /**
     * 响应体
     */
    private T respBody;
    /**
     * 强签名值
     */
    private String signatureValue;

    public ResponseMessage() {
    }

    public ResponseMessage(RespHead respHead, T respBody, String signatureValue) {
        this.respHead = respHead;
        this.respBody = respBody;
        this.signatureValue = signatureValue;
    }

    public RespHead getRespHead() {
        return respHead;
    }

    public void setRespHead(RespHead respHead) {
        this.respHead = respHead;
    }

    public T getRespBody() {
        return respBody;
    }

    public void setRespBody(T respBody) {
        this.respBody = respBody;
    }

    public String getSignatureValue() {
        return signatureValue;
    }

    public void setSignatureValue(String signatureValue) {
        this.signatureValue = signatureValue;
    }

    public static ResponseMessage success(RespHead respHead, Object respBody, String signatureValue) {
        ResponseMessage responseMessage = new ResponseMessage<>();
        responseMessage.setSignatureValue(signatureValue);
        responseMessage.setRespBody(respBody);
        responseMessage.setRespHead(respHead);
        return responseMessage;
    }

    public static ResponseMessage success(RespHead respHead) {
        ResponseMessage responseMessage = new ResponseMessage<>();
        responseMessage.setSignatureValue(null);
        responseMessage.setRespBody(null);
        responseMessage.setRespHead(respHead);
        return responseMessage;
    }

    public static ResponseMessage fail(RespHead respHead, Object respBody, String signatureValue) {
        ResponseMessage responseMessage = new ResponseMessage<>();
        responseMessage.setSignatureValue(signatureValue);
        responseMessage.setRespBody(respBody);
        responseMessage.setRespHead(respHead);
        return responseMessage;
    }

    public static ResponseMessage fail(RespHead respHead) {
        ResponseMessage responseMessage = new ResponseMessage<>();
        responseMessage.setSignatureValue(null);
        responseMessage.setRespBody(null);
        responseMessage.setRespHead(respHead);
        return responseMessage;
    }
}
